    # ###########补充itsdangerous的使用####################
# 加密过程
# 1 导入库
from meiduo_mall import settings
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer

# 2.创建一个实例对象
# secret_key,       秘钥，通常使用seeting 文件中的CESRET_KEY
# expires_in=None       过期时间  默认3600秒  （一个小时）
s = Serializer(secret_key=settings.SECRET_KEY,expires_in=3600)

# 3.有原始数据
data = {
    "openid":"abcdefg"
}
# 4.加密数据
s.dumps(data)

# b'eyJleHAiOjE1NzE1ODc5MjMsImlhdCI6MTU3MTU4NDMyMywiYWxnIjoiSFM1MTIifQ.eyJvcGVuaWQiOiJhYmNkZWZnIn0.pXMy4LOgd6f2LjxjSdhP9xkCc51Eeoif-TFEpA8mipFMchFXmsFeRiW0_NgzBuaRPhGB-Lm6UUAISl8UmhdUYA'


# 解密数据的过程
# 1.到入库.
from meiduo_mall import settings
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
# 2.创建实例对象,加密的时候要和解密的参数一致
s = Serializer(secret_key=settings.SECRET_KEY,expires_in=3600)
# 3.得有加密数据
secret_data='eyJleHAiOjE1NzE1ODc5MjMsImlhdCI6MTU3MTU4NDMyMywiYWxnIjoiSFM1MTIifQ.eyJvcGVuaWQiOiJhYmNkZWZnIn0.pXMy4LOgd6f2LjxjSdhP9xkCc51Eeoif-TFEpA8mipFMchFXmsFeRiW0_NgzBuaRPhGB-Lm6UUAISl8UmhdUYA'
# 4. 解密数据
s.loads(secret_data)

###############解密数据有可能存在异常######################
# 解密数据的过程
# 1.到入库.
from meiduo_mall import settings
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
# 2.创建实例对象,加密的时候要和解密的参数一致
s = Serializer(secret_key=settings.SECRET_KEY,expires_in=3600)
# 3.得有加密数据
# 此处被篡改任何一个就会异常
secret_data='eyJleHAiOjE1NzE1ODc5MjMsImlhdCI6MTU3MTU4NDMyMywiYWxnIjoiSFM1MTIifQ.eyJvcGVuaWQiOiJhYmNkZWZnIn0.pXMy4LOgd6f2LjxjSdhP9xkCc51Eeoif-TFEpA8mipFMchFXmsFeRiW0_NgzBuaRPhGB-Lm6UUAISl8UmhdUYA'
# 4. 解密数据
s.loads(secret_data)

#################如果数据过期了也会出现异常#########################

from meiduo_mall import settings
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer

# 2.创建一个实例对象
# secret_key,       秘钥，通常使用seeting 文件中的CESRET_KEY
# expires_in=None       过期时间  默认3600秒  （一个小时）
s = Serializer(secret_key=settings.SECRET_KEY,expires_in=1)
# 3.有原始数据
data = {
    "openid":"abcdefg"
}
# 4.加密数据
s.dumps(data)
s.loads(secret_data)